package thread.内部api;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class ConditionDe {


    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();

        ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(100);
        Condition one = lock.newCondition();
        Condition two = lock.newCondition();

        for (int i = 0; i < 7; i++) {
            int finalI = i;
            threadPoolExecutor.execute(() -> {

                lock.lock();
                System.out.println("我开始 了 " + finalI);

                try {
                    one.await();
                    System.out.println(finalI);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    lock.lock();

                }
            });
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < 8; i++) {
            threadPoolExecutor.execute(new Runnable() {
                @Override
                public void run() {

                    lock.lock();
                    one.signal();
//                two.signalAll();
                    lock.unlock();
                }
            });
        }





    }
}
